<?php
include '../Module/ProductModule.php';
$Module=new ProductModule();
if(isset($_REQUEST["action"])){
    switch ($_REQUEST["action"]){
        case "add":
            $name		=isset($_REQUEST["name"])?EndcodeStr($_REQUEST["name"]):"";
            $title		=isset($_REQUEST["title"])?EndcodeStr($_REQUEST["title"]):"";
            $description	=isset($_REQUEST["des"])?EndcodeStr($_REQUEST["des"]):"";
            $smallimage		=isset($_REQUEST["smallimage"])?EndcodeStr($_REQUEST["smallimage"]):"";
            $image		=isset($_REQUEST["image"])?EndcodeStr($_REQUEST["image"]):"";
            $price		=isset($_REQUEST["price"])?EndcodeStr($_REQUEST["price"]):"";
            $album		=isset($_REQUEST["album"])?($_REQUEST["album"]):0;
            if($Module->insert($name,$title,$description,$smallimage,$image,$price,$album)){
                echo "true";
            }else{
                echo "Lỗi rồi<br/>".$Module->error;
            }
            break;
        case "edit":
            $id                 =isset($_REQUEST["id"])?EndcodeStr($_REQUEST["id"]):"";
            $name		=isset($_REQUEST["name"])?EndcodeStr($_REQUEST["name"]):"";
            $title		=isset($_REQUEST["title"])?EndcodeStr($_REQUEST["title"]):"";
            $description	=isset($_REQUEST["des"])?EndcodeStr($_REQUEST["des"]):"";
            $smallimage		=isset($_REQUEST["smallimage"])?EndcodeStr($_REQUEST["smallimage"]):"";
            $image		=isset($_REQUEST["image"])?EndcodeStr($_REQUEST["image"]):"";
            $price		=isset($_REQUEST["price"])?EndcodeStr($_REQUEST["price"]):"";
            $album		=isset($_REQUEST["album"])?($_REQUEST["album"]):0;
            if($Module->update($id,$name,$title,$description,$smallimage,$image,$price,$album)){
                echo "true";
            }else{
                echo "Lỗi rồi<br/>".$Module->error;
            }
            break;
            break;
        case "delete":
            $id		=isset($_REQUEST["id"])?EndcodeStr($_REQUEST["id"]):"";
            if($Module->delete($id)){
                echo "true";
            }else{
                echo "Lỗi rồi<br/>".$Module->error;
            }
            break;
        case "restore":
            $id		=isset($_REQUEST["id"])?EndcodeStr($_REQUEST["id"]):"";
            if($Module->restore($id)){
                echo "true";
            }else{
                echo "Lỗi rồi<br/>".$Module->error;
            }
            break;
    }    
}
?>
